package com.dwxt.race.dao;

import com.dwxt.race.entity.Race;
import com.dwxt.race.entity.RaceExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

public interface RaceMapper {
    int countByExample(RaceExample example);

    int deleteByExample(RaceExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(Race record);

    int insertSelective(Race record);

    List<Race> selectByExample(RaceExample example);

    Race selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") Race record, @Param("example") RaceExample example);

    int updateByExample(@Param("record") Race record, @Param("example") RaceExample example);

    int updateByPrimaryKeySelective(Race record);

    int updateByPrimaryKey(Race record);

    /**
     * 扣减报名库存
     * @return
     */
    @Update("update race set registered_number = registered_number + #{num}  where id =#{raceId} and max_person > registered_number")
    int updateByOrder(Integer raceId, Integer num);

    /**
     * 支付失败
     * @return
     */
    @Update("update race set registered_number = registered_number - #{num}  where id =#{raceId} and max_person >= registered_number and registered_number > 0")
    int updateByPayBack(Integer raceId, Integer num);
}